import router from './router'
import store from './store'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
// import getPageTitle from '@/utils/get-page-title'
import { isRouter1, isRouter2, isRouter3 } from '@/router/index.js';

NProgress.configure({ showSpinner: false }) // NProgress Configuration

//const whiteList = ['/'] // no redirect whitelist

router.beforeEach(async (to, from, next) => {
  
  // start progress bar
  NProgress.start()

  // set page title
  // document.title = getPageTitle(to.meta.title)

  // 获取token
  const hasToken = store.getters.access_token
  const meta = to.meta || {}
   //判断token是否有效
  if (hasToken) {
    //token有效
    if (to.path === '/login') {
      // if is logged in, redirect to the home page
      next({ path: '/' })
   } else {
     next()
    }
  } else {
    //这里是没有token的跳转白名单
    if (meta.auth === 'pass') {
      next()
    } else {
     //next(`/login?redirect=${to.path}`)
    next({ path: '/login' })
    }
  }
})

router.afterEach(() => {
  // finish progress bar
  NProgress.done()
})
